package server;

import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Simple serveur TCP creant des thread pour gerer chaque connexion client.
 * 
 * @author lom
 */
public class FTPServerMain {

        /**
         * Port d'ecoute.
         */
        public static final int PORT = 7800;
        /**
         * Socket serveur d'accueil.
         */
        private static ServerSocket socketaccueil;
        /**
         * Le nombre de connexion possible au serveur 
         */
        private static final int numberOfConnection = 100;
        
        
        public static void main(String argv[]) throws Exception 
        
        {
        		ExecutorService connectionPool = Executors.newFixedThreadPool(numberOfConnection);
                try {
                		
                	
                        socketaccueil = new ServerSocket(PORT);
                        System.out.println("Server up and running.");
                        FTPServer.setDebug(true);
                        while (true) {
                                FTPServer server = new FTPServer(socketaccueil.accept());
                                connectionPool.submit(server);
                        }
                } finally {
                		connectionPool.shutdown();
                        if (socketaccueil != null) {
                                socketaccueil.close();
                        }
                }
        }
}